package com.wx.controller.api;

import com.wx.common.WrapMapper;
import com.wx.common.Wrapper;
import com.wx.domain.dto.StatisticsDto;
import com.wx.domain.vo.ChangeReasonVo;
import com.wx.domain.vo.EchartsVo;
import com.wx.holder.WxUserHolder;
import com.wx.service.SysPatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.chanjar.weixin.common.bean.WxOAuth2UserInfo;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * <p>Title:	  weixin-go-with-you <br/> </p>
 * <p>Description TODO <br/> </p>
 * <p>Company:    医百科技有限公司  <br/> </p>
 *
 * @Author <a href="yangwensheng@100doc.com.cn"/>杨文生</a>  <br/>
 * @Date 2021/4/7 9:35
 */
@RestController
@RequestMapping(value = "/api/index", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(tags = "工作台首页(API)", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ApiIndexController {

    @Resource
    private SysPatientService sysPatientService;

    @Resource
    private WxUserHolder wxUserHolder;


    @GetMapping(value = "/statistics/{type}")
    @ApiOperation(httpMethod = "GET", value = "统计在组、待随访、脱组、入组患者的数量")
    public Wrapper<List<EchartsVo>> indexStatistics(@PathVariable("type") Integer type) {
        WxOAuth2UserInfo userInfo = wxUserHolder.getUserInfo();
        List<EchartsVo> echartsVoList = sysPatientService.apiIndexStatistics(userInfo.getOpenid(),type);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, echartsVoList);
    }

    @PostMapping(value = "/prescriptionsNum")
    @ApiOperation(httpMethod = "POST", value = "处方人数")
    public Wrapper<List<BigDecimal>> prescriptionsNum(@RequestBody StatisticsDto statisticsDto) {
        WxOAuth2UserInfo userInfo = wxUserHolder.getUserInfo();
        List<BigDecimal> echartsVoList = sysPatientService.prescriptionsNum(userInfo.getOpenid(),statisticsDto);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, echartsVoList);
    }

    @PostMapping(value = "/prescriptionsPercentage")
    @ApiOperation(httpMethod = "POST", value = "处方占比")
    public Wrapper<List<BigDecimal>> prescriptionsPercentage(@RequestBody StatisticsDto statisticsDto) {
        WxOAuth2UserInfo userInfo = wxUserHolder.getUserInfo();
        List<BigDecimal> echartsVoList = sysPatientService.prescriptionsPercentage(userInfo.getOpenid(),statisticsDto);
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, echartsVoList);
    }

    @GetMapping(value = "/changeReason")
    @ApiOperation(httpMethod = "GET", value = "转化原因")
    public Wrapper<ChangeReasonVo> changeReason() {
        WxOAuth2UserInfo userInfo = wxUserHolder.getUserInfo();
        ChangeReasonVo changeReasonVo = sysPatientService.changeReason(userInfo.getOpenid());
        return WrapMapper.wrap(Wrapper.SUCCESS_CODE, Wrapper.SUCCESS_MESSAGE, changeReasonVo);
    }
}
